<template>
  <div>
    <div class="mb20">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
        <el-form-item label="识别码" prop="lastname">
          <el-input v-model="queryParams.lastname" placeholder="请输入用户识别码" clearable @keyup.enter.native="getData" />
        </el-form-item>
        <el-form-item label="用户名称" prop="userName">
          <el-input v-model="queryParams.userName" placeholder="请输入用户名称" clearable style="width: 240px" @keyup.enter.native="getData" />
        </el-form-item>
        <el-form-item label="用户昵称" prop="nickName">
          <el-input v-model="queryParams.nickName" placeholder="请输入用户昵称" clearable @keyup.enter.native="getData" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phonenumber">
          <el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable @keyup.enter.native="getData" />
        </el-form-item>
        <el-form-item label="用户邮箱" prop="email">
          <el-input v-model="queryParams.email" placeholder="请输入用户邮箱" clearable @keyup.enter.native="getData" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getData">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-table :data="userList" v-loading="loading" border stripe style="width: 100%">
      <el-table-column prop="avatarurl" label="头像" width="110">
        <template slot-scope="scope">
          <image-preview :src="scope.row.avatar" :width="80" :height="80" shape="circle" />
        </template>
      </el-table-column>
      <el-table-column prop="nickName" label="昵称" width="100">
        <template slot-scope="scope">
          {{ scope.row.nickName }}
        </template>
      </el-table-column>
      <el-table-column prop="lastname" label="识别码" width="80"> </el-table-column>
      <el-table-column prop="phonenumber" label="电话" width="120"> </el-table-column>
      <el-table-column prop="email" label="邮箱" width="200"> </el-table-column>
      <el-table-column prop="tariff" label="选择">
        <template slot-scope="scope">
          <el-button type="primary" plain size="mini" @click="select(scope.$index)">选择</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getData" />
    <!-- 分页结束 -->

  </div>
</template>

<script>
import {
  listUser
} from "@/api/system/user";
export default {
  name: 'userSelect',
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 6,
        lastname: null,
        userName: undefined,
        nickName: null,
        phonenumber: undefined,
        email: undefined
      },
      total: 0, // 总数据
      loading: true, // 是否打开loading
      userList: [], // 表格数据
    }
  },
  components: {
    // 组件
  },
  computed: {
    // 计算属性,里面是个方法
  },
  methods: {
    /**
     * 选择按钮被点击
     */
    select(index) {
      this.$emit('submit', this.userList[index])
    },
    // 获取数据
    async getData() {
      this.loading = true;
      listUser(this.queryParams).then(response => {
          console.log('userlist:', response);
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
  },
  mounted() {
    this.getData()
  },
}
</script>

<style scoped>
.avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
}
</style>
